package com.ykq.service.impl;

import com.ykq.dao.UserDao;
import com.ykq.entity.User;
import com.ykq.service.UserService;
import com.ykq.util.CommonResult;
import com.ykq.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: 145ssm
 * @description:
 * @author: 闫克起2
 * @create: 2021-12-10 09:11
 **/
@Service(value = "userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    public CommonResult findUserByUsernameAndPassword(String username, String password) {
        User user=userDao.selectByUsernameAndPassword(username,password);
        if(user==null){
            return new CommonResult(5000,"账号或密码错误",null);
        }
        if(user.getStatus()==1){
           return new CommonResult(5000,"该账号已被冻结",null);
        }
        if(user.getStatus()==2){
            return new CommonResult(5000,"该账户已注销",null);
        }
        //在任意地方可以获取session对象。
        WebUtil.getSession().setAttribute("user",user);
        return new CommonResult(2000,"登录成功",null);
    }
}



